include('shared.lua')

hitList2 = hitList2 or {}
local flashTimer = flashTimer or true
function ENT:Draw()
	self:DrawModel()

	local Pos = self:GetPos()
	local Ang = self:GetAngles()

	
	if hitList2[1] and hitList2[1] != {} then
			if LocalPlayer():Team()==TEAM_HITMAN or LocalPlayer():Team()==TEAM_PROHITMAN then
				
				surface.SetFont("HUDNumber5")
				local TextWidth = surface.GetTextSize("Ring ring, motherfucker!")

				Ang:RotateAroundAxis(Ang:Forward(), 90)
				Ang:RotateAroundAxis(Ang:Right(), -90)
				local TextAng = Ang

				//TextAng:RotateAroundAxis(TextAng:Right(), CurTime() * -180)
				if flashTimer then 
					flashTimer=false
					timer.Create("flashThePhone",4,1,function() makeFadingLight(self) end)
				end
				
				//cam.Start3D2D(Pos + Ang:Right() * -30, TextAng, 0.2)
				//	draw.WordBox(2, -TextWidth*0.5 + 5, -90, "Ring ring, motherfucker!!", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
				//cam.End3D2D()
		end
	end
end

function makeFadingLight(ent)
	print("making light")
	flashTimer=true

	local dlight2 = DynamicLight( 0 )
	if ( dlight2 ) then
		local r, g, b, a = ent:GetColor()
		dlight2.Pos = ent:GetPos() + Vector(0,0,20)
		dlight2.r = 255
		dlight2.g = 0
		dlight2.b = 0
		dlight2.Brightness = 8
		dlight2.Size = 256
		dlight2.Decay = 70
		dlight2.DieTime = CurTime() + 3
        dlight2.Style = 0
	end

	sound.Play( "buttons/bell1.wav", ent:GetPos() )

end

function openclHitMenu(e, hitList)

	hitList2 = hitList
	//print(1)
	//PrintTable(hitList2)
	if tonumber(LocalPlayer().DarkRPVars.money) < tonumber(250) then
		GAMEMODE:AddNotify("You don't have enough money to order a hit!",NOTIFY_ERROR,4)
		return
	end

	local hitMenu = vgui.Create( "DFrame" )
	hitMenu:SetSize( 320, 500 )
	hitMenu:SetPos( 0 , 0 )
	hitMenu:SetTitle( "Destiny is calling, obey me or defy me..." )
	hitMenu:SetVisible( true )
	hitMenu:SetDraggable( true )
	hitMenu:ShowCloseButton( true )
	hitMenu:MakePopup()

	local tabHolder = vgui.Create( "DPropertySheet", hitMenu )
	tabHolder:SetPos( 0, 30 )
	tabHolder:SetSize( hitMenu:GetWide(), hitMenu:GetTall()-30)
	 
	local hireTab = vgui.Create( "DFrame" )
	hireTab:SetPos( 0, 30 ) -- Set the position of the panel
	hireTab:SetSize( tabHolder:GetWide(), tabHolder:GetTall() ) -- Set the size of the panel
	hireTab:SetTitle( "" )
	hireTab:SetVisible( true )
	hireTab:SetDraggable( false )
	hireTab:ShowCloseButton( false )
	//hireTab:SetAlpha(255)

		local label1 = vgui.Create("DLabel", hireTab)
		label1:SetText("Who do you want taken out?")
		label1:SetPos(10,30)
		label1:SetColor(Color(0,0,0,255))
		label1:SizeToContents()

		local playersList = vgui.Create( "DComboBox", hireTab )
		playersList:SetSize(285,20)
		playersList:SetPos( 10, 45 )
		getAllDaPlayers = player.GetAll()
		playersList:SetValue(getAllDaPlayers[1]:Name())
		for k,v in pairs(getAllDaPlayers) do
			playersList:AddChoice(v:Name())
		end

		local label2 = vgui.Create("DLabel", hireTab)
		label2:SetText("How much are you willing to pay?  $\n\n\n\n\n\n\n YOU ARE NOT ALLOWED TO FILL OUT YOUR OWN HITS!")
		label2:SetPos(10,80)
		label2:SetColor(Color(0,0,0,255))
		label2:SizeToContents()

		local hitPrice = vgui.Create( "DNumSlider", hireTab )
		hitPrice:SetPos( 200,71 )
		hitPrice:SetWide( 50 )
		hitPrice:SetMin( 250 ) -- Minimum number of the slider
		hitPrice:SetMax( tonumber(LocalPlayer().DarkRPVars.money) ) -- Maximum number of the slider
		hitPrice:SetDecimals( 0 ) -- Sets a decimal. Zero means it's a whole number
		hitPrice:SetValue(250)
		hitPrice:SizeToContents()

		local doHitButton = vgui.Create( "DButton", hireTab )
		doHitButton:CenterHorizontal()
		local butPosX,butPosY = doHitButton:GetPos()
		doHitButton:SetPos(butPosX,100)
		doHitButton:SetWide( 50 )
		doHitButton:SetText("Hire")
		doHitButton:SetSize(60,40)
		doHitButton.DoClick = function() 

			//local price = hitPrice:GetValue()
			//local money = LocalPlayer().DarkRPVars.money

			//if price >= money then return end

			for k,v in pairs(player.GetAll()) do 
				if v:Name()==playersList:GetValue() then 
					plyUID=v:UniqueID()
				end
			end
			hittable = {Player=plyUID,Price=hitPrice:GetValue(),Placedby=LocalPlayer():UniqueID()}
			net.Start("placeHit")
				net.WriteTable(hittable)
			net.SendToServer()
			hitMenu:Close()
		end

	tabHolder:AddSheet( "Hire Guns", hireTab, "icon16/gun.png", false, false )

	if LocalPlayer():Team()==TEAM_HITMAN or LocalPlayer():Team()==TEAM_PROHITMAN then
		local hitsTab = vgui.Create( "DFrame" )
		hitsTab:SetPos( 0, 30 ) -- Set the position of the panel
		hitsTab:SetSize( tabHolder:GetWide(), tabHolder:GetTall() ) -- Set the size of the panel
		hitsTab:SetTitle( "" )
		hitsTab:SetVisible( true )
		hitsTab:SetDraggable( false )
		hitsTab:ShowCloseButton( false )

		local hitListView = vgui.Create("DListView" , hitsTab)
		hitListView:SetPos(2, 2)
		hitListView:SetSize(hitsTab:GetWide()-20, tabHolder:GetTall()-150)
		hitListView:SetMultiSelect(false)
		hitListView:AddColumn("Target") -- Add column
		hitListView:AddColumn("Price")
		hitListView:AddColumn("Placed By")

		for k,v in pairs(hitList) do
			for i,w in pairs(player.GetAll()) do
				if w:UniqueID()==v.Player then
					 hitListView:AddLine(w:Name(),v.Price,player.GetByUniqueID(v.Placedby):Name())
				end
		    end
		end

		tabHolder:AddSheet( "View Jobs", hitsTab, "icon16/flag_red.png", false, false )
	end

end

net.Receive("openclHitMenu", function() openclHitMenu(net.ReadInt(4), net.ReadTable()) end)

net.Receive("lostHit", function() GAMEMODE:AddNotify("You just lost a hit, get on the ball!",NOTIFY_ERROR,4) end)

net.Receive("updateHitList", function() hitList2=net.ReadTable() end)